import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'

export const constantRoutes = [
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },

  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },

  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    children: [{
      path: 'dashboard',
      name: '云医疗管理平台',
      component: () => import('@/views/dashboard/index'),
      meta: { title: '首页', icon: 'el-icon-s-platform' }
    }]
  },
  {
    path: '/user',
    component: Layout,
    name: 'User',
    meta: { title: '用户管理', icon: 'el-icon-s-custom' },
    children: [
      {
        path: 'list',
        name: 'list',
        component: () => import('@/views/user/List'),
        meta: { title: '用户列表', icon: 'table' }
      },
      {
        path: 'add',
        name: 'Add',
        component: () => import('@/views/user/Add'),
        meta: { title: '用户新增', icon: 'tree' }
      }
    ]
  },
  {
    path: '/nurse',
    component: Layout,
    name: 'Nurse',
    meta: { title: '护士管理', icon: 'el-icon-s-help' },
    children: [
      {
        path: 'list',
        name: 'List',
        component: () => import('@/views/nurse/List'),
        meta: { title: '护士列表', icon: 'table' }
      },
      {
        path: 'add',
        name: 'Add',
        component: () => import('@/views/nurse/Add'),
        meta: { title: '护士新增', icon: 'tree' }
      }
    ]
  },
  {
    path: '/day',
    component: Layout,
    name: 'Day',
    meta: { title: '药品管理', icon: 'el-icon-s-help' },
    children: [
      {
        path: 'list',
        name: 'List',
        component: () => import('@/views/medication/List'),
        meta: { title: '药品列表', icon: 'table' }
      },
      {
        path: 'add',
        name: 'Add',
        component: () => import('@/views/medication/Add'),
        meta: { title: '药品新增', icon: 'tree' }
      }
    ]
  },
  // {
  //   path: '/nurse',
  //   component: Layout,
  //   name: 'Nurse',
  //   meta: { title: '护士管理', icon: 'el-icon-s-help' },
  //   children: [
  //     {
  //       path: 'list',
  //       name: 'List',
  //       component: () => import('@/views/medication/List'),
  //       meta: { title: '药品列表', icon: 'table' }
  //     },
  //     {
  //       path: 'add',
  //       name: 'Add',
  //       component: () => import('@/views/medication/Add'),
  //       meta: { title: '药品新增', icon: 'tree' }
  //     }
  //   ]
  // },
  {
    path: '/question',
    component: Layout,
    name: 'Question',
    meta: { title: '管理', icon: 'el-icon-s-help' },
    children: [
      {
        path: 'list',
        name: 'List',
        component: () => import('@/views/medication/List'),
        meta: { title: '问题列表', icon: 'table' }
      },
      {
        path: 'add',
        name: 'Add',
        component: () => import('@/views/medication/Add'),
        meta: { title: '问题新增', icon: 'tree' }
      }
    ]
  },
  {
    path: '/comment',
    component: Layout,
    name: 'Comment',
    meta: { title: '意见反馈', icon: 'el-icon-s-help' },
    children: [
      {
        path: 'list',
        name: 'List',
        component: () => import('@/views/medication/List'),
        meta: { title: '反馈列表', icon: 'table' }
      },
      {
        path: 'add',
        name: 'Add',
        component: () => import('@/views/medication/Add'),
        meta: { title: '新增反馈', icon: 'tree' }
      }
    ]
  }
]

const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
